﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EmoneyWeiXinEntity;
using EmoneyWeiXinBLL;
using EmoneyWeiXinCommon;
using EmoneyWeiXin.Filter;
namespace EmoneyWeiXin.Controllers
{
    public class CustomAccountManagerController : Controller
    {
        //
        // GET: /CustomAccountManager/
          [LoginAuthorizeAttribute]
        public ActionResult Index()
        {
            ViewBag.leftid = int.Parse(Request["leftid"]);
            return View();
        }
        //查询客服账号列表
        public string GetCustomAccountList()
        {
            var strJson = "";
            var total = 0;
            var pindex = int.Parse(Request["index"]);
            var psize = int.Parse(Request["size"]);
            var weixinid = int.Parse(Request["weixinid"]);
            var list = CustomAccountManagerBLL.getCustomAccountManagerList(pindex, psize, weixinid, out  total);
            if (list != null)
                strJson = JsonTools.ToJson(list);
            return total + "~" + strJson;
        }
        //根据id查询客服账号
        public string GetCustomAccountListByID()
        {
            var strJson = "";
            var id = int.Parse(Request["id"]);
            var list = CustomAccountManagerBLL.getCustomAccountManagerListByID(id);
            if (list != null)
                strJson = JsonTools.ToJson(list);
            return strJson;
        }
        //更新客服账号方法
        public string UpdateCustomAccount()
        {
            var uid = 0;
            UserEntity us = LoginUserInfo.GetLoginUserCache();
            if (us != null)
                uid = us.id;
            var op = int.Parse(Request["op"]);
            var id = int.Parse(Request["id"]);
            var ire = 0;
            if (op != -1)//编辑操作
            {
                var weixinid = int.Parse(Request["weixinid"]);
                var account = Request["account"];
                var pwd = Request["pwd"];
                var isvalid = 1;
                var obj = new CustomAccountManagerEntity();
                obj.id = id;
                obj.account = account;
                obj.pwd = pwd;
                obj.isvalid = isvalid;
                obj.createtime = DateTime.Now;
                obj.updatetime = DateTime.Now;
                obj.weixinid = weixinid;
                obj.creator = uid;
                ire = CustomAccountManagerBLL.UpdateCustomAccountManager(obj);
            }
            else//删除操作
            {
                ire = CustomAccountManagerBLL.DeleteCustomAccountManager(id);
            }
            return ire.ToString();
        }

    }
}
